var zigzagLevelOrder = function (root) {
  if (!root) return [];
  let res = [],
      queue = [root],
      level = 0;
  while (queue.length) {
    res[level] = [];
    let len = queue.length; // 第 level 层的节点数量
    while (len--) {
      let cur = queue.shift();
      res[level].push(cur.val);
      cur.left && queue.push(cur.left);
      cur.right && queue.push(cur.right);
    }
    if (level % 2) {
      res[level].reverse();
    }
    level++;
  }
  return res;
}